﻿using System.Drawing;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using E4RPDevExpress;
using E4RPTools;

namespace Fitecom
{
    public partial class MainRibbonForm : RibbonForm
    {

        private Controller _controller;

        #region Properties

        public Controller Controller
        {
            set
            {
                _controller = value;
                _controller.OwnerWindow = this;
                //workOrdersXtraUserControl.Controller = _controller;
                //salesXtraUserControl.Controller = _controller;
                //contractTypesXtraUserControl.Controller = _controller;
                //serviceTypesXtraUserControl.Controller = _controller;
                //serviceDesignationXtraUserControl.Controller = _controller;
                //userListXtraUserControl.Controller = _controller;
                //ControlsVisibility();
            }
        }

        #endregion

        public MainRibbonForm()
        {
            InitializeComponent();
            synchronizeClientsButtonItem.ItemClick += SynchronizeClientsButtonItemItemClick;
            synchronizeSuppliersBarButtonItem.ItemClick += SynchronizeSuppliersBarButtonItemItemClick;
            synchronizeArticlesBarButtonItem.ItemClick += SynchronizeArticlesBarButtonItemItemClick;
            synchronizeCompoundsBarButtonItem.ItemClick += SynchronizeCompoundsBarButtonItemItemClick;
            synchronizeStocksBarButtonItem.ItemClick += SynchronizeStocksBarButtonItemItemClick;
            aboutBarButtonItem.ItemClick += AboutBarButtonItemItemClick;
            exitBarButtonItem.ItemClick += ExitBarButtonItemItemClick;
            Closing += MainRibbonForm_Closing;
        }
        
        void SynchronizeClientsButtonItemItemClick(object sender, ItemClickEventArgs e)
        {
            _controller.SynchronizeClients();
        }

        void SynchronizeArticlesBarButtonItemItemClick(object sender, ItemClickEventArgs e)
        {
            _controller.SynchronizeArticles();
        }

        void SynchronizeSuppliersBarButtonItemItemClick(object sender, ItemClickEventArgs e)
        {
            _controller.SynchronizeSuppliers();
        }

        void SynchronizeCompoundsBarButtonItemItemClick(object sender, ItemClickEventArgs e)
        {
            _controller.SynchronizeCompounds();
        }

        void SynchronizeStocksBarButtonItemItemClick(object sender, ItemClickEventArgs e)
        {
            _controller.SynchronizeStocks();
        }

        static void AboutBarButtonItemItemClick(object sender, ItemClickEventArgs e)
        {
            var product = new AboutLabelControl("Fitecom", new Font("Jokerman", 20F, FontStyle.Regular, GraphicsUnit.Point, 0), Color.ForestGreen, new Point(127, 38));
            var form = new AboutXtraForm { Version = "1.0.0.0", Product = product };
            form.ShowDialog();
        }

        void ExitBarButtonItemItemClick(object sender, ItemClickEventArgs e)
        {
            _controller.CloseConnections();
            Close();
        }

        void MainRibbonForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            _controller.CloseConnections();
        }

    }
}